#ifndef H_LED
#define H_LED

#include "Arduino.h"

#ifdef STANDARD 
#define LED 13
#else
#error ERROR led.h NO LED Board defined
#endif

class Led
{
private:
  byte state,output;
  int rate0,rate1;
  int count;
public:
  void setup()
  {
    pinMode(LED,OUTPUT);
    rate0=rate1=0.5*CYCLERATE;
  }

  void setOutput(byte o)
  {
    output=o;
    if (output==0) // slow blink
    {
      rate0=rate1=1.0*CYCLERATE;
    }

    else if (output==1)
    {
      rate0=0.5*CYCLERATE;
      rate1=0.05*CYCLERATE;
    }
    else if (output==2) // fast blink
    {
      rate1=0.05*CYCLERATE;
      rate0=0.05*CYCLERATE;
    }

  }

  void update()
  {
    switch(state)
    {
    case 0: 
      digitalWrite(LED,HIGH);
      state=10;
      count=0;
      break;
    case 10:
      if (count++>=rate1)
        state=20;
      break;
    case 20:
      digitalWrite(LED,LOW);
      state=30;
      count=0;
      break;
    case 30:
      if (count++>rate0)
        state=0;
      break;       
    }

  }
} 
led;

#endif




